﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CalculatorLib.Interface;
using CalculatorLib.Model;

namespace CalculatorLib
{
    public class Calculator
    {

        private CalModel _data;

        private IBasicCalculator _calculator;

        public Calculator()
        {
            this._calculator = new BasicCalculator();    
        }


        #region Property
        public CalModel Data
        {
            get { return _data; }
            set { _data = value; }
        }
        #endregion

        #region Methods
        public int Calculate()
        {
            int retval = 0;
            if (this.Data != null)
            {
                switch (this.Data.Operation)
                { 
                    case CalOperation.Add:
                        if (this.Data.CalMode == CalMode.Single)
                        {
                            retval = this._calculator.Add(this.Data.IntegerValue1, this.Data.IntegerValue2);
                        }
                        else
                        {
                            retval = this._calculator.ComplexListOperation(this.Data.ListOfIntegerValue, CalOperation.Add);
                        }
                        break;
                    case CalOperation.Sub:
                        if (this.Data.CalMode == CalMode.Single)
                        {
                            retval = this._calculator.Sub(this.Data.IntegerValue1, this.Data.IntegerValue2);
                        }
                        else
                        {
                            retval = this._calculator.ComplexListOperation(this.Data.ListOfIntegerValue, CalOperation.Sub);
                        }
                        break;
                    case CalOperation.Mul:
                        if (this.Data.CalMode == CalMode.Single)
                        {
                            retval = this._calculator.Mul(this.Data.IntegerValue1, this.Data.IntegerValue2);
                        }
                        else
                        {
                            retval = this._calculator.ComplexListOperation(this.Data.ListOfIntegerValue, CalOperation.Mul);
                        }
                        break;
                    case CalOperation.Div:
                        if (this.Data.CalMode == CalMode.Single)
                        {
                            retval = this._calculator.Div(this.Data.IntegerValue1, this.Data.IntegerValue2);
                        }
                        else
                        {
                            retval = this._calculator.ComplexListOperation(this.Data.ListOfIntegerValue, CalOperation.Div);
                        }
                        break;
                }
            }
            else
            {
                Console.WriteLine("There is no data");
            }
            return retval;
        }
        #endregion

        
    }

    public enum CalOperation { Add, Mul, Sub, Div, AddList };
    public enum CalMode { Single, List};
}
